Listing 1: Member fr den REST-Service anlegen

public RestService
{
  @Context
  private UriInfo uri;

  @POST
@Path( "/members" )
public Response createNewMember( MemberModel memberModel )
{
  // ... speichere den Member 
  final String id = saveMemberModel( memberModel ); 

  final URI uri = uri.getAbsolutePathBuilder( ).path( id ).build( );
    return Response.created( uri ).build( );

}

  // weitere Methoden 

}



Listing 2: Details zur Konvertierung in JSON per Annotation

@JsonTypeInfo( use =JsonTypeInfo.Id.NAME, include = As.PROPERTY )
public abstract class MemberModel 
{
  @JsonSerialize( using = ObjectIdSerializer.class )
  protected ObjectId id;

  @Ref( value = "/members/{id}", style = Style.ABSOLUTE, 
bindings = { @Binding( name = "id", value = "${instance.id}" ) } )
  @XmlElement
  @Transient
  protected URI href;

  // bei den Attributen userName gibt es keine weiteren Annotationen 

  @Updateable
  @JsonSerialize( using = PasswordSerializer.class )
  protected String password;

}


Listing 3: Methode zum Laden eines Objekts in Verbindung mit Ortsabfrage

@GET
@Path( "/places" )
public Response getPlaceModels( @QueryParam( "lng" ) double longitude, 
@QueryParam( "lat" ) double latitude, @QueryParam( "radius" ) double radius )		
{
  final List<PlaceModel> result = datastore.find( PlaceModel.class)
  .field( "loc" ).within( longitude, latitude, radius / 111.12 );
  GenericEntity<List<PlaceModel>> entity = 
  new GenericEntity<List<PlaceModel>>( result ) {};
  return Response.ok( entity ).build( );
}


Listing 4: Methode zum Laden eines Place-Objekts

public Place loadPlaceFromServer( final String placeHref )
{
Place returnValue = new Place();
  try
  {
    final DefaultHttpClient httpClient = new DefaultHttpClient();
final HttpGet request = new HttpGet( new URI( placeHref ) );

request.setHeader( "Accept", "application/json" );

final HttpResponse httpResponse = httpClient.execute( request );

if( httpResponse.getStatusLine().getStatusCode() == 200 )
{
  final InputStream is = httpResponse.getEntity().getContent();
returnValue.fromJson( copyStreamToString( is ) );
return returnValue;
}
return null;
}
catch( final Exception e )
{
  Log.e( "network", "Problem with get from server", e );
return null;
}
}



Listing 5: Signup und Login mit dem Parse-SDK

class LoginButtonListener implements OnClickListener {
@Override
public void onClick(View v) {
    IntereaActivity.this.processLoginDialog = ProgressDialog.show(
IntereaActivity.this, "", "Please wait ...", true);
    final String email =((TextView) findViewById(R.id.editText1)). 
getText().toString();
    final String password =( (TextView) findViewById(R.id.editText2)).
getText().toString();
    ParseUser.logInInBackground(email,password, new LogInCallback() {
        @Override
        public void done(ParseUser userFromLogin, ParseException exception) {
          if(exception==null){
          //Login OK
            IntereaActivity.this.myHandler.sendEmptyMessage(0);
          }
          else {
            //Wrong Password
            //...
            //Sign Up
            ParseUser parseUser=new ParseUser();
            parseUser.setUsername(email);
            parseUser.setPassword( password);
            parseUser.signUpInBackground(new SignUpCallback() {
              @Override
              public void done(ParseException ex) {
                if(ex!=null) {
                  //Handle Error
                } IntereaActivity.this.myHandler.sendEmptyMessage(0);	
              }
            });
           }
         }
    });
  }
}
